package com.aibili.contoller.administrator;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.aibili.contoller.BaseController;
import com.aibili.pojo.ChargeRecord;
import com.aibili.pojo.model.PageBodyModel;
import com.aibili.pojo.model.PageModel;
import com.aibili.service.ChatService;
import com.daoshun.common.CommonUtils;
import com.daoshun.common.DsConstant;

@Controller
@RequestMapping("/administrator")
public class ChargeController extends BaseController {

	@Resource
	private ChatService chatService;

	@RequestMapping("/chargerecordinfo")
	public ModelAndView chargeRecordInfo(String mobile, Integer pageIndex, String start_time, String end_time) {
		ModelAndView mav = new ModelAndView();

		if (pageIndex == null || pageIndex <= 0) {
			pageIndex = 1;
		}

		mav.addObject("start_time", start_time);
		mav.addObject("end_time", end_time);
		if (!CommonUtils.isEmptyString(start_time) && start_time.length() < 17) {
			start_time = start_time + " 00:00:00";
		}
		if (!CommonUtils.isEmptyString(end_time) && end_time.length() < 17) {
			end_time = end_time + " 23:59:59";
		}

		PageBodyModel<ChargeRecord> results = chatService.getchargeRecord(pageIndex, DsConstant.PAGESIZE, mobile,
				start_time, end_time);
		if (results != null) {
			List<ChargeRecord> users = results.getList();
			PageModel page = results.getPageModel();
			mav.addObject("list", users);
			mav.addObject("page", page);
		}
		mav.addObject("mobile", mobile);
		return mav;
	}

	@RequestMapping("/exchange")
	public ModelAndView exchangeRecord(String mobile, Integer pageIndex, String start_time, String end_time) {
		ModelAndView mav = new ModelAndView();

		if (pageIndex == null || pageIndex <= 0) {
			pageIndex = 1;
		}

		mav.addObject("start_time", start_time);
		mav.addObject("end_time", end_time);
		if (!CommonUtils.isEmptyString(start_time) && start_time.length() < 17) {
			start_time = start_time + " 00:00:00";
		}
		if (!CommonUtils.isEmptyString(end_time) && end_time.length() < 17) {
			end_time = end_time + " 23:59:59";
		}

		PageBodyModel<ChargeRecord> results = chatService.getexchangeRecord(pageIndex, DsConstant.PAGESIZE, mobile,
				start_time, end_time);
		if (results != null) {
			List<ChargeRecord> users = results.getList();
			PageModel page = results.getPageModel();
			mav.addObject("list", users);
			mav.addObject("page", page);
		}
		mav.addObject("mobile", mobile);
		return mav;
	}

}
